package com.situ.day3;

import org.junit.Test;

public class WhileForDemo {

    /*循环的三要素：
    1、循环条件的初始化
    2、循环条件的控制 count
    3、循环条件的改变*/
    @Test
    public void test1() {
        int i = 1;
        while (i <= 100) {
            System.out.println("HelloWorld count");
            //要打印下一次
            i++;//101
        }
        //....
    }

    @Test
    public void test2() {
        int count = 0;
        for (int i = 1; i <= 10; i++) {
            System.out.println("HelloWorld");
        }
    }

    @Test
    public void test3() {
        int count = 0;
        for (int i = 1; i <= 5; i++) {
            System.out.println(i);
        }
    }

    //1、累加思想（1+2+3+... + 100）
    //写代码：你怎么想的就怎么表达出来
    @Test
    public void test55() {
        int i = 1;
        int sum = 0;
        while (i <= 100) {
            sum = sum + i;
            System.out.println("i: " + i);
            System.out.println("sum: " + sum);
            i++;
        }
        System.out.println("sum: " + sum);
    }

    // sum += i;  sum = sum + i;
    // sum -= i;  sum = sum - i;
    // sum *= i;  sum = sum * i;
    // sum /= i;  sum = sum / i;
    @Test
    public void test554() {
        int sum = 0;
        for (int i = 1; i <= 100; i++) {
            sum += i;// sum = sum + i;
            System.out.println("i: " + i);
            System.out.println("sum: " + sum);
        }
        System.out.println("sum: " + sum);
    }

    //2、统计思想，数一下符合条件的有多少个（计算1-100以内7的倍数的个数）
    @Test
    public void test44() {
        int count = 0;
        for (int i = 1; i <= 100; i++) {
            if (i % 7 == 0) {
                System.out.println("i: " + i);
                count++;
            }
        }
        System.out.println("count: " + count);
    }









}
